#include <lpc23xx.h>
#include "LCD.h"
#define DMA_SRC			0x7FD00100
#define DMA_DST			0x7FD00500
#define DMA_SIZE		0x100

unsigned int i;

volatile unsigned int item2[4] = {0x7FD00100,0x7FD00700,0,0x8C4A4040};
volatile unsigned int item1[4] = {0x7FD00100,0x7FD00600,(unsigned int)item2,0x0C4A4040};

unsigned int *Buffer1,*Buffer2;

int main (void)
{
     Buffer1 = (unsigned int *)DMA_SRC;          //Set the start address of the source buffer
	 Buffer2 = (unsigned int *)DMA_DST;          //Set the start address of the destination buffer

    lcd_init();					   //
	lcd_clear();				  //
	set_cursor(2,0);			   // Agaf=/
    lcd_print("Scatter Gather");	 //
	 
	 for ( i = 0; i < DMA_SIZE/4; i++ )          //Initilise the buffers
	 {
		*Buffer1 = i;
		*Buffer2 = 0;
		Buffer1++;
		Buffer2++;
	}

	PCONP |= (0x1<<29);                           // Power up the GPDMA
	GPDMA_CONFIG = 0x01;	                      // Enable the GPDMA
	while ( !(GPDMA_CONFIG & 0x01) );             // Wait until the GPDMA is operational
	 
    GPDMA_INT_TCCLR      = 0x01;                   //Clear the interrupt status bits
    GPDMA_INT_ERR_CLR   = 0x01;
    GPDMA_CH0_SRC       = DMA_SRC;                //Load buffer1 start address into Channel 0
	GPDMA_CH0_DEST      = DMA_DST;                //Load buffer2 start address into Channel0
	GPDMA_CH0_CTRL      = ((DMA_SIZE/4) & 0x0FFF) //set the transfer size
	                   | (0x04 << 12)             // Source burst size 
	                   | (0x04 << 15)             //destination burst size  
			           | (0x02 << 18)             //Source width
			           | (0x02 << 21)             //destination width
			           | (1 << 26)                //Source increment
			           | (1 << 27);               //Destination increment
			           
	GPDMA_CH0_LLI       = (unsigned int ) item1;
	GPDMA_CH0_CFG      |= 0x08001;                 //Start the channel zero transfer
	
//	while ( !GPDMA_RAW_INT_TCSTAT );                //Wait until the transfer has finished

   
	while(1)
	   {
	   
	       ;
	   }

//return (0);    
}
